package com.sys.web.action;

import com.sys.dao.model.RightSettings;
import com.sys.base.action.BaseGftAction;
import com.sys.plat.bean.PageBean;
import com.sys.plat.util.HttpUtil;
import com.sys.plat.web.core.ActionContext;
import com.sys.service.RightSettingsService;
import com.sys.web.form.RightSettingsForm;

public class RightSettingsAction extends BaseGftAction {

    public String find() {
        RightSettingsForm rightSettingsForm = (RightSettingsForm) ActionContext.getForm();
        PageBean pageBean = createPageBean(rightSettingsForm);
        RightSettingsService rightSettingsService = (RightSettingsService) getService("gRightSettingsServiceImpl");
        rightSettingsService.listRightSettings(pageBean);
        pageBean.setToWeb();
        HttpUtil.saveSearchParemeter();
        HttpUtil.reqSetAttr("fmap", rightSettingsForm.getFilter());
        return "list";
    }

    public String edit() {
        RightSettingsForm rightSettingsForm = (RightSettingsForm) ActionContext.getForm();
        RightSettings rightSettings = rightSettingsForm.getR();
        RightSettingsService rightSettingsService = (RightSettingsService) getService("gRightSettingsServiceImpl");
        if (null != rightSettings.getId() && !"".equals(rightSettings.getId())) {
            rightSettings = rightSettingsService.editRightSettings(rightSettings);
            HttpUtil.reqSetAttr("r", rightSettings);
            HttpUtil.saveSearchParemeter();
        }
        return "edit";
    }

    public String update() {
        RightSettingsForm rightSettingsForm = (RightSettingsForm) ActionContext.getForm();
        RightSettings rightSettings = rightSettingsForm.getR();
        RightSettingsService rightSettingsService = (RightSettingsService) getService("gRightSettingsServiceImpl");
        rightSettingsService.addOrUpdateRightSettings(rightSettings);
        if (null == rightSettings.getId() || "".equals(rightSettings.getId()))
            addMsg("ADD_OK");
        else
            addMsg("EDIT_OK");
        return edit();
    }

    public String delete() {
        RightSettingsForm rightSettingsForm = (RightSettingsForm) ActionContext.getForm();
        RightSettingsService rightSettingsService = (RightSettingsService) getService("gRightSettingsServiceImpl");
        rightSettingsService.deleteRightSettings(rightSettingsForm.getIds());
        return find();
    }
}
